package cn.iocoder.yudao.module.crm.service.cluetranslog;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.crm.controller.admin.cluetranslog.vo.*;
import cn.iocoder.yudao.module.crm.dal.dataobject.cluetranslog.ClueTransLogDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.crm.dal.mysql.cluetranslog.ClueTransLogMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;

/**
 * 规则执行记录 Service 实现类
 *
 * @author 数创万维
 */
@Service
@Validated
public class ClueTransLogServiceImpl implements ClueTransLogService {

    @Resource
    private ClueTransLogMapper clueTransLogMapper;

    @Override
    public Long createClueTransLog(ClueTransLogSaveReqVO createReqVO) {
        // 插入
        ClueTransLogDO clueTransLog = BeanUtils.toBean(createReqVO, ClueTransLogDO.class);
        clueTransLogMapper.insert(clueTransLog);
        // 返回
        return clueTransLog.getId();
    }

    @Override
    public void updateClueTransLog(ClueTransLogSaveReqVO updateReqVO) {
        // 校验存在
//        validateClueTransLogExists(updateReqVO.getId());
        // 更新
        ClueTransLogDO updateObj = BeanUtils.toBean(updateReqVO, ClueTransLogDO.class);
        clueTransLogMapper.updateById(updateObj);
    }

    @Override
    public void deleteClueTransLog(Long id) {
        // 校验存在
//        validateClueTransLogExists(id);
        // 删除
        clueTransLogMapper.deleteById(id);
    }

//    private void validateClueTransLogExists(Long id) {
//        if (clueTransLogMapper.selectById(id) == null) {
//            throw exception(CLUE_TRANS_LOG_NOT_EXISTS);
//        }
//    }

    @Override
    public ClueTransLogDO getClueTransLog(Long id) {
        return clueTransLogMapper.selectById(id);
    }

    @Override
    public PageResult<ClueTransLogDO> getClueTransLogPage(ClueTransLogPageReqVO pageReqVO) {
        return clueTransLogMapper.selectPage(pageReqVO);
    }

}